﻿Type=Class
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@

Sub Class_Globals
	Private nativeMe As JavaObject
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
	nativeMe.InitializeContext
End Sub
'https://www.b4x.com/android/forum/threads/roundbitmapwithborder-inline-java-code.51848/#post-380801
Public Sub getRoundBmp(bmin As Bitmap,borderWidth1 As Int,borderColor1 As Int) As Bitmap
	Dim nativeMe As JavaObject
	nativeMe.InitializeContext
	Dim retbm As Bitmap=nativeMe.RunMethod("getRoundBitmap",Array(bmin,borderColor1, borderWidth1)) 
	Return retbm
End Sub
Public Sub getSquareBmp(bmin As Bitmap,borderWidth2 As Int,borderColor2 As Int) As Bitmap
	Dim nativeMe As JavaObject
	nativeMe.InitializeContext
    Dim bm2 As Bitmap = nativeMe.RunMethod("addSquareBorder",Array(bmin, borderWidth2, borderColor2))  
	Return bm2
End Sub
#If Java

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Path.FillType;
import android.graphics.Paint;
import android.graphics.Color;
import android.view.View;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.BitmapShader;
import android.graphics.Shader;
import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff.Mode;


public static Bitmap getRoundBitmap(Bitmap scaleBitmapImage, int borderColor, int borderWidth) {
    int targetWidth = 1000;
    int targetHeight = 1000;
    int radius = Math.min((targetHeight - 5)/2, (targetWidth - 5)/2);  
   
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
            Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth - 1) / 2,
            ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
            Path.Direction.CCW);

    canvas.clipPath(path);
   
    Bitmap sourceBitmap = scaleBitmapImage;
   
    canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
            sourceBitmap.getHeight()), new Rect(0, 0, targetWidth,
            targetHeight), null);
           
           
    Paint p = new Paint();                                             
    p.setAntiAlias(true);                  
    //    canvas.drawBitmap(sourceBitmap, 4, 4, p);                                     
    p.setXfermode(null);                                               
    p.setStyle(Paint.Style.STROKE);                                          
    p.setColor(borderColor);                                           
    p.setStrokeWidth(borderWidth);                                               
    canvas.drawCircle((targetWidth / 2) , (targetHeight / 2) , radius, p);                             

    return targetBitmap;
}   
   
    public static Bitmap addSquareBorder(Bitmap bmp, int borderSize, int bordercolor) {
           
        Bitmap bmpWithBorder = Bitmap.createScaledBitmap(bmp, bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, false);           
           
        Canvas canvas = new Canvas(bmpWithBorder);
        canvas.drawColor(bordercolor);
        canvas.drawBitmap(bmp, borderSize, borderSize, null);
        return bmpWithBorder;
    }   
   
   


#End If